﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="主表ID（主表ID）" prop="ParentId">
          <a-input v-model="entity.ParentId" autocomplete="off" placeholder="主表ID（主表ID）" />
        </a-form-model-item>
        <a-form-model-item label="货区Id" prop="AreaId">
          <a-input v-model="entity.AreaId" autocomplete="off" placeholder="货区Id" />
        </a-form-model-item>
        <a-form-model-item label="货架Id" prop="RackId">
          <a-input v-model="entity.RackId" autocomplete="off" placeholder="货架Id" />
        </a-form-model-item>
        <a-form-model-item label="货位Id" prop="LocationId">
          <a-input v-model="entity.LocationId" autocomplete="off" placeholder="货位Id" />
        </a-form-model-item>
        <a-form-model-item label="物料Id" prop="MaterialId">
          <a-input v-model="entity.MaterialId" autocomplete="off" placeholder="物料Id" />
        </a-form-model-item>
        <a-form-model-item label="备货数量" prop="StockVolume">
          <a-input v-model="entity.StockVolume" autocomplete="off" placeholder="备货数量" />
        </a-form-model-item>
        <a-form-model-item label="已经备货数量" prop="ReadyNums">
          <a-input v-model="entity.ReadyNums" autocomplete="off" placeholder="已经备货数量" />
        </a-form-model-item>
        <a-form-model-item label="销售订单子表Id" prop="SaleOrderItemId">
          <a-input v-model="entity.SaleOrderItemId" autocomplete="off" placeholder="销售订单子表Id" />
        </a-form-model-item>
        <a-form-model-item label="状态：0-默认；1-全部出货；2-未全部出货" prop="State">
          <a-input v-model="entity.State" autocomplete="off" placeholder="状态：0-默认；1-全部出货；2-未全部出货" />
        </a-form-model-item>
        <a-form-model-item label="已发货数量" prop="ShippedNums">
          <a-input v-model="entity.ShippedNums" autocomplete="off" placeholder="已发货数量" />
        </a-form-model-item>
        <a-form-model-item label="批次号" prop="Batch">
          <a-input v-model="entity.Batch" autocomplete="off" placeholder="批次号" />
        </a-form-model-item>
        <a-form-model-item label="物料批次唯一" prop="LineId">
          <a-input v-model="entity.LineId" autocomplete="off" placeholder="物料批次唯一" />
        </a-form-model-item>
        <a-form-model-item label="备注" prop="Remarks">
          <a-input v-model="entity.Remarks" autocomplete="off" placeholder="备注" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/PB/PB_ShippingNoticeItem/GetTheData', { id: id }).then(resJson => {
          this.loading = false
          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/PB/PB_ShippingNoticeItem/SaveData', this.entity).then(resJson => {
          this.loading = false
          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.loading = false
            this.visible = false
	        this.$emit('returnMain')
          } else {
            this.$message.error(resJson.Msg)
            this.loading = false
          }
        })
      })
    },
    // 非空校验
    validEmpty (index, name, tips) {
      return (rule, value, callback) => {
        const data = this.DetaiData[index][name]
        if (!data) {
          this.$message.warning('列表第' + (index + 1) + '行：' + tips)
          callback(tips || '必填')
        } else {
          callback()
        }
      }
    }
  }
}
</script>
<style scoped>
</style>
